require('dotenv').config();
const https = require('https');
const md5 = require('md5');
const axios = require('axios');
const apiUrl = 'http://api.fanyi.baidu.com/api/trans/vip/translate';
const appid = '20180912000205796';
const secret = 'KO8S_D2NeoBgPHUY5kGg';

const requestTranslate = (q) => {
    const salt = Math.random();
    const sign = md5(appid + q + salt + secret);
    const params = {
        q,
        from: 'zh',
        to: 'en',
        salt,
        appid,
        sign,
    };
    return axios.get(apiUrl, {
        params,
    });
};

module.exports = { requestTranslate };